package scheduleFile;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import schedule.Schedule;

import net.fortuna.ical4j.data.CalendarBuilder;
import net.fortuna.ical4j.data.CalendarOutputter;
import net.fortuna.ical4j.data.ParserException;
import net.fortuna.ical4j.model.Calendar;
import net.fortuna.ical4j.model.ValidationException;

/**
 * Permet de charger et de sauvegarder un emploi du temps dans le format ICS
 * @author Stanislas KOBAK / Celine BARILLERE
 *
 */
public class IcsFile
{
	public Schedule load(InputStream inputStream) throws IOException, ParserException
	{		
		CalendarBuilder builder = new CalendarBuilder();
		Calendar calendar = builder.build(inputStream);			
		return new Schedule(calendar);
	}

	public void save(Schedule schedule, FileOutputStream outputStream) throws IOException, ValidationException
	{
		Calendar calendar = schedule.toCalendar();
		CalendarOutputter outputter = new CalendarOutputter();
		outputter.output(calendar, outputStream);
	}
}